package Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class BasicServlet
 */
@WebServlet("/BasicServlet")
public class BasicServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public BasicServlet() {
        // TODO Auto-generated constructor stub
    }
    
//    @Override
//    public void init(ServletConfig config) throws ServletException
//	{
//    	
//    	System.out.println("init method is done!!");
//		super.init(config);
//	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		// TODO Auto-generated method stub
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		String sid = request.getSession().getId();
		
		out.println("<html>");
		out.println("<head><title>This is Repple's Home ~</title></head>");
		out.println("<body>");
		out.println("Hello Repple, now is " + df.format(new Date()) + "<br>");
		out.println("Your request method was " + request.getMethod() + "<br>");
		out.println("Your session id was " + sid);
		out.println("</body></html>");
		out.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		// TODO Auto-generated method stub
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		String sid = request.getSession().getId();
			
		out.println("<html>");
		out.println("<head><title>This is Repple's Home ~</title></head>");
		out.println("<body>");
		out.println("Hello Repple, now is " + df.format(new Date()) + "<br>");
		out.println("Your request method was " + request.getMethod() + "<br>");
		out.println("Your session id was " + sid);
		out.println("</body></html>");
		out.close();
	}
	
	//get Servlet information
	public String getServletInfo()
	{
		return "BasicServlet information";
	}

//	@Override
//	public void destroy() {
//		// TODO Auto-generated method stub
//		
//		System.out.println("destroy method did!!");
//		super.destroy();
//	}
	
	

}
